﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using HuynhQuangWebsite.Models;
using THS.HtmlHelpers;

namespace HuynhQuangWebsite.Controllers
{
    public class Tin_tucController : BaseController
    {
        //
        // GET: /NewsPage/
        readonly huynhquangco_websiteEntities ctx = new huynhquangco_websiteEntities();
        public int PageSize = 6;
        public ActionResult Danh_sach(int page = 1)
        {
            var model = new HomeListViewModel();
            IList<News> news = ctx.News.Where(p => p.NewIsVisible).OrderByDescending(p=>p.NewsID).ToList();
            model.NewsFocusList = news.Skip((page-1) * PageSize).Take(PageSize).ToList();
            model.NewsInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = news.Count() };
            return View(model);
        }
        //
        public ActionResult Paging(int page = 1)
        {
            var model = new HomeListViewModel();
            IList<News> news = ctx.News.Where(p => p.NewIsVisible).OrderByDescending(p=>p.NewsID).ToList();
            model.NewsFocusList = news.Skip((page-1) * PageSize).Take(PageSize).ToList();
            model.NewsInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = news.Count() };
                return PartialView("UCNewList", model);
           
        }
        public ActionResult Chi_tiet(int id)
        {

            var model = new DetailsListViewModel();
            News objNews = ctx.News.Where(p => p.NewsID == id).SingleOrDefault();
            model.CurrentNews = objNews;
            model.FlagID = objNews.NewsID;
            //get top recent news
            IList<News> news = ctx.News.OrderByDescending(p => p.AACreateDate).Take(5).ToList();
            model.NewList = news;
            return View();
        }
    }
}
